package com.yyds.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyds.common.MyJSON;
import com.yyds.mapper.PreventPersonMapper;
import com.yyds.pojo.PreventPerson;
import com.yyds.service.PreventPersonService;
import com.yyds.vo.PreventPersonVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service("preventPersonService")
public class PreventPersonServiceImpl implements PreventPersonService {

    @Autowired
    private PreventPersonMapper preventPersonMapper;//DI自动注入
    @Override
    public MyJSON<PreventPersonVo> selectAllPreventPersonService(Map<String, Object> params) {
        //mybatis分页插件的使用
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params.get("limit")+"");

        PageHelper.startPage(page,limit);
        List<PreventPersonVo> preventPersonList =  preventPersonMapper.selectByParams(params);

        //mybatis的分页数据结构
        PageInfo<PreventPersonVo> preventPersonPageInfo = new PageInfo<>(preventPersonList);
        //把mybatis的分页数据结构中的数据封装到layui的分页数据结构中
        MyJSON<PreventPersonVo> preventPersonMyJSON = new MyJSON<>();
        preventPersonMyJSON.setCode(0);
        preventPersonMyJSON.setMsg("封控人员分页列表数据");
        preventPersonMyJSON.setCount(preventPersonPageInfo.getTotal());  // 总记录数
        preventPersonMyJSON.setData(preventPersonPageInfo.getList());  // 分页列表数据

        return preventPersonMyJSON;
    }

    @Override
    public int deletePreventPersonService(Integer person_id) {
        return preventPersonMapper.deletePreventPersonMapper(person_id);
    }

    @Override
    public PreventPerson selectPreventPersonService(Integer person_id) {

        return preventPersonMapper.selectPreventPersonMapper(person_id);
    }


}
